import $ from 'jquery'
import jquery from 'jquery'
function Api() {
    //this.host = "";
    this.host = "";
    //this.host = "http://127.0.0.1:8911";
    //this.host = "http://47.101.221.173:99";
    this.domain = "http://mmhf.sjunjie.cn";
    //this.domain = "http://127.0.0.1:8911";
    this.apiUrl = "/api";
    this.pre = "mmhf";
    //this.pre = "";
    this.server = this.host + this.apiUrl + this.pre;


    this.test = this.server + "/test";
//===============================基础basice===================================//
    this.basic = new Object();
    this.basic.allProducts = this.server + "/allProducts";
    this.basic.allAreas = this.server + "/allAreas";
    this.basic.productCategory = this.server + "/getCache";
    // 登陆
    this.basic.login =this.host + this.apiUrl+ "/account/login";
//===============================订单order===================================//
    this.order = new Object();
    this.order.orders = this.server + "/orders";
    this.order.order = this.server + "/order";
    this.order.searchOrder = this.server + "/order/search";
//===============================出库outStorage===================================//
    this.outStorage = new Object();
    this.outStorage.outStorage = this.server + "/outStorage";
    this.outStorage.outStorages = this.server + "/outStorages";
    this.outStorage.searchOutStorage = this.server + "/outStorage/search";
    // 出库
    this.outStorage.outStorageOut = this.server + "/outStorage/out";
    // 发货
    this.outStorage.outStorageSend = this.server + "/outStorage/send";
//===============================店铺管理e===================================//
    this.storeManage = new Object();
    this.storeManage.calculateWages = this.server + "/calculateWages"
    //============================支出明细==================================//
    this.expendDetail = new Object()
    this.expendDetail.batch = this.server + "/getExpendDetailList";
    // 添加明细
    this.expendDetail.addDetail = this.server + "/addDetail";
    this.expendDetail.deleteDetail = this.server + "/deleteDetail";
    this.expendDetail.getPrice = this.server + "/getPrice";

    // ===========================数据处理=========================================//
    this.dataAnalysis = new Object();
    this.dataAnalysis.excel = this.server + "/file/excel";
    this.dataAnalysis.excels = this.server + "/file/excels";
    this.dataAnalysis.downloadAnalysis = this.server + "/file/excel/export";
}

var $Api = new Api();

/**
 * 返回状态
 */
var $ResponseCode = new function () {
    this.ok = 200;
    this.noLogin = 401;
};

/**
 * 模拟深拷贝
 * @param source
 * @returns {Object}
 */
window.copy = function (source) {
    var obj = new Object();
    for (var key in source) {
        obj[key] = source[key];
    }
    return obj;
};
/**
 * 模拟深拷贝
 * @param source
 */
window.copy2 = function (source) {
    var obj = JSON.parse(JSON.stringify(source));
    return obj;
};

/**
 * 字典
 */
var $Dictionary = new function () {
    this.source = [
        {
            key: "手淘搜索",
            value: 101
        },
        {
            key: "微信",
            value: 102
        },
        {
            key: "购物车",
            value: 103
        },
        {
            key: "我的淘宝",
            value: 104
        },
        {
            key: "手淘首页",
            value: 105
        },
        {
            key: "其他",
            value: 106
        },
        {
            key: "淘内免费",
            value: 107
        },
        {
            key: "淘宝",
            value: 108
        }
    ]
    this.expendType = [
        {
            name: "物品购买",
            value: "1"
        },
        {
            name: "店铺充值",
            value: "2"
        },
        {
            name: "服务费",
            value: "3"
        },
        {
            name: "红包返现",
            value: "4"
        },
        {
            name: "项目支出",
            value: "5"
        },
        {
            name: "其他",
            value: "10"
        }
    ]
};

// 全局ajax回调
// $.ajaxSetup({
//     type: "POST",
//     error: function (jqXHR, textStatus, errorMsg) { // 出错时默认的处理函数
//         vm.layer.msg('操作异常<br />' + jqXHR.status,function(){
// //关闭后的操作
//         });
//     }
// });

/**
 * 失败通知信息
 * @param _this
 * @param resp 两个参数是为后台接口返回对象，三三个参数时为title
 * @param msg
 */
window.failedNotify = function (_Toast, message) {

    _Toast({
        message: message,
        iconClass: 'iconfont icon-Group-',
        duration: 2000
    });
    $('.mint-toast.is-placemiddle').css("z-index", "3000")

//关闭后的操作
};

/**
 * format格式化增强date
 * @param fmt
 * @returns {*}
 * @constructor
 */
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1,                 //月份
        "d+": this.getDate(),                    //日
        "h+": this.getHours(),                   //小时
        "m+": this.getMinutes(),                 //分
        "s+": this.getSeconds(),                 //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds()             //毫秒
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};

/**
 * 成功通知信息
 * @param _this
 * @param resp 两个参数是为后台接口返回对象，三三个参数时为title
 * @param msg
 */
window.successNotify = function (_Toast, message) {
    _Toast({
        message: message,
        iconClass: 'iconfont icon-dui',
        duration: 1000
    });
    $('.mint-toast.is-placemiddle').css("z-index", "3000")
};

window.checkEmpty = function (obj) {
    if (obj === null || obj === undefined || obj === 0 || obj === "") {
        return false
    }
    if (obj instanceof String) {
        if (obj === "" || parseInt(obj) === 0) {
            return false;
        }
    } else if (obj instanceof Array) {
        if (obj.length == 0) {
            return false
        }
    } else if (obj instanceof Number) {
        if (obj == 0) {
            return false
        }
    }

    return true;
}

/**
 * 检查设备
 */
window.checkPCorMobile = function () {
    // alert(document.body.clientHeight)
    console.log("5")
    var flag = IsPC(); //true为PC端，false为手机端
    if (flag) {
        window.location.href = $Api.domain + "/pc/phone.html"
    }
}

/**
 * pc检查
 * @returns {boolean}
 * @constructor
 */
function IsPC() {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["Android", "iPhone",
        "SymbianOS", "Windows Phone",
        "iPad", "iPod"];
    var flag = true;
    for (var v = 0; v < Agents.length; v++) {
        if (userAgentInfo.indexOf(Agents[v]) > 0) {
            flag = false;
            break;
        }
    }
    return flag;
}
window.getRequest=function() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        var strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}
/**
 * jquery validate 中文message
 */
$(function () {
    var icon = "<i class='fa fa-times-circle'></i>  ";
    jquery.extend(jquery.validator.messages, {
        required: icon + "必填",
        remote: icon + "请修正此栏位",
        email: icon + "请输入有效的电子邮件",
        url: icon + "请输入有效的网址",
        date: icon + "请输入有效的日期",
        dateISO: icon + "请输入有效的日期 (YYYY-MM-DD)",
        number: icon + "请输入正确的数字",
        digits: icon + "只能输入数字",
        creditcard: icon + "请输入有效的信用卡号码",
        equalTo: icon + "你的输入不相同",
        extension: icon + "请输入有效的后缀",
        maxlength: jquery.validator.format(icon + "最多 {0} 个字"),
        minlength: jquery.validator.format(icon + "最少 {0} 个字"),
        rangelength: jquery.validator.format(icon + "请输入长度为 {0} 至 {1} 之间的字串"),
        range: jquery.validator.format(icon + "请输入 {0} 至 {1} 之间的数值"),
        max: jquery.validator.format(icon + "请输入不大于 {0} 的数值"),
        min: jquery.validator.format(icon + "请输入不小于 {0} 的数值")
    });
});

export { //很关键
    $Api, $ResponseCode, $Dictionary
}




